home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / omniORB-2.5.0-src.tar.gz / omniORB-2.5.0-src.tar / omniORB_2.5.0 / include / omniORB2 / omniLC.h < prev    next >
C/C++ Source or Header  |  1997-12-18  |  7KB  |  326 lines

  1. // -*- Mode: C++; -*-
  2. //                            Package   : omniORB2
  3. // omniLifeCycle.cc           Created on: 1997/09/20
  4. //                            Author    : Duncan Grisby (dpg1)
  5. //
  6. //    Copyright (C) 1997 Olivetti & Oracle Research Laboratory
  7. //
  8. //    This file is part of the omniORB library
  9. //
  10. //    The omniORB library is free software; you can redistribute it and/or
  11. //    modify it under the terms of the GNU Library General Public
  12. //    License as published by the Free Software Foundation; either
  13. //    version 2 of the License, or (at your option) any later version.
  14. //
  15. //    This library is distributed in the hope that it will be useful,
  16. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. //    Library General Public License for more details.
  19. //
  20. //    You should have received a copy of the GNU Library General Public
  21. //    License along with this library; if not, write to the Free
  22. //    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
  23. //    02111-1307, USA
  24. //
  25. //
  26. // Description:
  27. //    *** PROPRIETORY INTERFACE ***
  28. //      
  29.  
  30. /* 
  31.    $Log: omniLC.h,v $
  32.    Revision 1.3  1997/12/18 17:37:33  sll
  33.    Added virtual dtor for _lc_sk.
  34.  
  35.    Revision 1.2  1997/12/10 13:45:10  sll
  36.    Cleanup to remove constructs that trigger the MSVC nested class bug.
  37.  
  38.  * Revision 1.1  1997/12/10 11:52:39  sll
  39.  * Initial revision
  40.  *
  41.  * Revision 1.1  1997/09/20  17:41:47  dpg1
  42.  * Initial revision
  43.  *
  44.  */
  45.  
  46. #ifndef _omniLC_h_
  47. #define _omniLC_h_
  48.  
  49.  
  50. #include <omnithread.h>
  51. #include <omniORB2/omniLifeCycle.hh>
  52.  
  53.  
  54. // Everything lives inside class omniLC:
  55.  
  56. class omniLC {
  57. public:
  58.  
  59.   //
  60.   // _wrap_home class -- base abstract class for home location wrappers:
  61.  
  62.   class _wrap_home {
  63.   protected:
  64.     omniObject *_dispatcher;    // Object to handle dispatch() calls
  65.  
  66.   public:
  67.     //
  68.     // Functions needed by omniLifeCycleInfo:
  69.  
  70.     virtual void _move(CORBA::Object_ptr to) = 0;
  71.     virtual void _remove() = 0;
  72.   };
  73.  
  74.  
  75.   //
  76.   // _wrap_proxy class -- base class for proxy object wrappers. Calls
  77.   // to a _wrap_proxy object normally resolve to calls to an _lc_proxy
  78.   // object. On receiving a LOCATION_FORWARD message, the object being
  79.   // wrapped is changed.
  80.  
  81.   class _wrap_proxy {
  82.   public:
  83.     _wrap_proxy() {
  84.       _next_wrap_proxy = 0;
  85.       _fwd  = 0;
  86.     };
  87.  
  88.     CORBA::Boolean _forwarded() {
  89.       return _fwd;
  90.     };
  91.  
  92.     // Register that this _wrap_proxy is wrapping the given local object
  93.     void _register_wrap(omniObject *obj);
  94.  
  95.     // Register that this _wrap_proxy is no longer wrapping a local object
  96.     void _unregister_wrap();
  97.  
  98.     // Reset all _wrap_proxies which are wrapping the given local object
  99.     static void _reset_wraps(omniObject *obj);
  100.  
  101.     // Reset the wrapper to use its original _proxy object (when the
  102.     // object moves back out of our address space).
  103.     virtual void _reset_proxy() = 0;
  104.  
  105.   protected:
  106.     CORBA::Boolean _fwd;        // Have we been forwarded?
  107.     _wrap_proxy *_next_wrap_proxy;
  108.  
  109.   private:
  110.     omniObjectKey _wrapped_key;
  111.   };
  112.  
  113.  
  114.   //
  115.   // Implementation class for LifeCycleInfo:
  116.  
  117.   class LifeCycleInfo_i
  118.     : public virtual _sk_omniLifeCycleInfo
  119.   {
  120.   private:
  121.     _wrap_home *wrap;
  122.     CORBA::Object_var  home;
  123.  
  124.   public:
  125.     LifeCycleInfo_i(_wrap_home *w, CORBA::Object_ptr h)
  126.       : wrap(w)
  127.     {
  128.       home = CORBA::Object::_duplicate(h);
  129.     };
  130.  
  131.     virtual ~LifeCycleInfo_i() { };
  132.  
  133.     void reportMove(CORBA::Object_ptr obj) {
  134.       wrap->_move(obj);
  135.     };
  136.  
  137.     void reportRemove() {
  138.       wrap->_remove();
  139.       CORBA::BOA::getBOA()->dispose(this);
  140.     };
  141.  
  142.     CORBA::Object_ptr homeObject() {
  143.       return CORBA::Object::_duplicate(home);
  144.     };
  145.   };
  146.  
  147.  
  148.   //
  149.   // _lc_sk class defines things common to all _lc_sk skeleton classes:
  150.  
  151.   class _lc_sk {
  152.   private:
  153.     omniLifeCycleInfo_var _linfo;
  154.  
  155.   protected:
  156.     void _set_linfo(omniLifeCycleInfo_ptr li) {
  157.       _linfo = omniLifeCycleInfo::_duplicate(li);
  158.     };
  159.     omniLifeCycleInfo_ptr _get_linfo() {
  160.       return _linfo;
  161.     };
  162.  
  163.   public:
  164.     virtual void _move(CORBA::Object_ptr to) = 0;
  165.     virtual void _remove() = 0;
  166.  
  167.     virtual ~_lc_sk() {}
  168.   };
  169.  
  170.  
  171.   //
  172.   // reDirect class creates an omniObject which sends LOCATION_FORWARD
  173.   // messages:
  174.  
  175.   class reDirect : public virtual omniObject, public virtual CORBA::Object {
  176.   public:
  177.  
  178.     reDirect(CORBA::Object_ptr fwdref); 
  179.     reDirect(CORBA::Object_ptr fwdref,const omniORB::objectKey& mykey);
  180.  
  181.     virtual ~reDirect() { }
  182.  
  183.     CORBA::Object_ptr forwardReference() const;
  184.  
  185.     CORBA::Object_ptr _this();
  186.     void _obj_is_ready(CORBA::BOA_ptr boa);
  187.     CORBA::BOA_ptr _boa();
  188.     void _dispose();
  189.     omniORB::objectKey _key();
  190.     virtual CORBA::Boolean dispatch(GIOP_S &s, const char *,CORBA::Boolean);
  191.  
  192.   private:
  193.     CORBA::Object_var pd_fwdref;
  194.     reDirect();
  195.   };
  196.  
  197.  
  198.   //
  199.   // _threadControl class helps look after concurrency in LifeCycle object
  200.   // implementations:
  201.  
  202.   class _threadControl {
  203.   public:
  204.  
  205.     _threadControl() {
  206.       _mu      = new omni_mutex;
  207.       _moveGo  = new omni_condition(_mu);
  208.       _running = 0;
  209.       _moving  = 0;
  210.     };
  211.  
  212.     virtual ~_threadControl() {
  213.       delete _moveGo;
  214.       delete _mu;
  215.     };
  216.  
  217.     //
  218.     // _beginOp() must be called at the start of all operations except
  219.     // ones which affect object existence:
  220.  
  221.     void _beginOp() {
  222.       _mu->lock();
  223.  
  224.       if (_moving) {
  225.     _mu->unlock();
  226.     throw CORBA::TRANSIENT(0,CORBA::COMPLETED_NO);
  227.       }
  228.  
  229.       _running++;
  230.       _mu->unlock();
  231.     };
  232.  
  233.     //
  234.     // _endOp() must be called at the end of operations started with
  235.     // _beginOp():
  236.  
  237.     void _endOp() {
  238.       _mu->lock();
  239.  
  240.       _running--;
  241.       if (_moving && (_running == 0))
  242.     _moveGo->signal();
  243.  
  244.       _mu->unlock();
  245.     };
  246.  
  247.     //
  248.     // _beginLC() must be called before all LifeCycle operations instead
  249.     // of _beginOp():
  250.  
  251.     void _beginLC() {
  252.       _mu->lock();
  253.  
  254.       if (_moving) {
  255.     _mu->unlock();
  256.     throw CORBA::TRANSIENT(0,CORBA::COMPLETED_NO);
  257.       }
  258.  
  259.       _moving = 1;
  260.  
  261.       if (_running > 0)
  262.     _moveGo->wait();
  263.  
  264.       _mu->unlock();
  265.     };
  266.  
  267.     //
  268.     // _endLC() must be called after operations started with _beginLC():
  269.  
  270.     void _endLC() {
  271.       _moving = 0;        // No concurrency control needed
  272.     };
  273.  
  274.   private:
  275.     omni_mutex     *_mu;
  276.     omni_condition *_moveGo;
  277.     CORBA::Long    _running;
  278.     CORBA::Boolean _moving;
  279.   };
  280.  
  281.  
  282.   //
  283.   // Two helper classes to make exception handling with the _threadControl
  284.   // class easier:
  285.  
  286. // Create a TheadOp object in all normal operations:
  287.  
  288.   class ThreadOp {
  289.   public:
  290.     ThreadOp(_threadControl *t)
  291.       : tc(t)
  292.     {
  293.       t->_beginOp();
  294.     };
  295.  
  296.     ~ThreadOp() {
  297.       tc->_endOp();
  298.     };
  299.  
  300.   private:
  301.     _threadControl *tc;
  302.   };
  303.  
  304.   // Create a ThreadLC object in all LifeCycle operations:
  305.  
  306.   class ThreadLC {
  307.   public:
  308.     ThreadLC(_threadControl *t)
  309.       : tc(t)
  310.     {
  311.       t->_beginLC();
  312.     };
  313.  
  314.     ~ThreadLC() {
  315.       tc->_endLC();
  316.     };
  317.  
  318.   private:
  319.     _threadControl *tc;
  320.   };
  321.  
  322. };
  323.  
  324.  
  325. #endif // _omniLC_h_
  326.